package com.timk.goserver.client.ui.screens;

import java.util.ArrayList;

import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.ClickListener;
import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;
import com.timk.goserver.client.model.GameInvite;
import com.timk.goserver.client.model.Message;

/**
 * Panel for displaying other users' data
 * @author TKington
 *
 */
public class ViewUserPanel extends Composite {
	final String username;	// NOPMD - Explicit scoping
	
	/**
	 * Creates a ViewUserPanel
	 * @param mainPanel the MainPanel
	 * @param username the username
	 */
	public ViewUserPanel(final MainPanel mainPanel, String username) {
		this.username = username;
		
		VerticalPanel panel = new VerticalPanel();
		
		HorizontalPanel buttonPanel = new HorizontalPanel();
		
		Button inviteButton = new Button("Invite");
		inviteButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				GameInvite invite = new GameInvite();
				ArrayList players = new ArrayList();
				players.add(MainPanel.loggedInUser.getUsername());
				players.add(ViewUserPanel.this.username);
				invite.setPlayers(players);
				
				InviteDialog dlg = new InviteDialog(null, invite, true);
				dlg.show();
			}
		});
		buttonPanel.add(inviteButton);
		
		Button messageButton = new Button("Send Message");
		messageButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				Message msg = new Message();
				msg.setFromUser(MainPanel.loggedInUser.getUsername());
				msg.setToUser(ViewUserPanel.this.username);
				MessageDialog dlg = new MessageDialog(msg, true);
				dlg.show();
			}
		});
		buttonPanel.add(messageButton);
		
		Button closeButton = new Button("Close");
		closeButton.addClickListener(new ClickListener() {
			public void onClick(Widget sender) {
				mainPanel.hideUser(ViewUserPanel.this.username);
			}
		});
		buttonPanel.add(closeButton);
		
		panel.add(buttonPanel);
		
		UserInfoPanel infoPanel = new UserInfoPanel(username);
		panel.add(infoPanel);
		
		GamelistPanel gamelistPanel = new GamelistPanel(mainPanel, username, false);
		panel.add(gamelistPanel);
		
		Label vertGlue = new Label(" ");
		panel.add(vertGlue);
		vertGlue.setHeight("100%");
		panel.setCellHeight(vertGlue, "100%");
		
		initWidget(panel);
	}
}
